function control() {
	this.obj = new getElement();
	this.startObj = '';
	this.againObj = '';
	this.ongoingObj = '';
	this.meet_id = '';
	this.sequence = '';
	this.gameTime= 0;
	this.getNumberTimer = '';
	this.timer=null;
	this.isLock = false;
	var that;
}
control.prototype = {
	status:'',
	gameTime:'',
	init:function() {
		that = this;
		that.status = $("#status").val();
		that.meet_id = that.obj.getQueryString("meet_id");
	    that.sequence = that.obj.getQueryString("sequence")
	    that.startObj = that.obj.getElem("start");
		that.againObj = that.obj.getElem("again");
		that.ongoingObj = that.obj.getElem("ongoing");
		that.nobodyObj = that.obj.getElem("nobody");
		//that.againObj.style.display="none";
	    that.gameTime = $("#time").val();
	    that.bindEvent();

		if(parseInt(that.status) == 1) {
			that.timer = setTimeout(function() {
				$("#nobody").removeClass("active");
				$("#ongoing").removeClass("active");
				$("#start").removeClass("active");
				$("#again").removeClass("active");
				that.ongoingObj.style.display = "none";
				that.startObj.style.display = "none";
				that.nobodyObj.style.display = "none";
				that.againObj.style.display = "block";
				that.status = 2;
				clearTimeout(that.timer);
			}, that.gameTime*1000);
		}
		if(that.gameTime < 0){
			that.ongoingObj.style.display = "none";
			that.startObj.style.display = "none";
			that.nobodyObj.style.display = "none";
			that.againObj.style.display=="block";
		}
		that.gamecheck();
	},
	bindEvent:function() {
		/**再来一次按钮绑定事件**/
		that.againObj.addEventListener("click",function() {
			that.gameAgain();
		},false);

		/**开始按钮绑定事件**/
		that.startObj.addEventListener("click",function() {
			that.gameStart();
		},false);
	},
	gameStart:function() {
		clearInterval(that.getNumberTimer);
		$.ajax({
            url:"/tug/screen/checkgamestatus",
            dataType:"json",
            type: "post",
            data:{
                "sequence":that.sequence,
				"meet_id":that.meet_id,
                "status" : 1,
            },
            success:function(data) {
                if(data.recode == 2){
                	if(data.status == 0) {		//游戏未开始	status : 0
						that.startObj.style.display = "none";
						that.ongoingObj.style.display = "block";
						that.gameStatus(1);
                	} else if(data.status == 1) {//游戏进行中  status : 1
                		that.startObj.style.display = "none";
						that.ongoingObj.style.display = "block";
						return ;
                	} else if(data.status == 2) {//游戏已结束	status : 2
                		that.gameStatus(0);
                		// window.location.reload();
                	}
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){

            }
        });
	},
	gameAgain:function() {
		$.ajax({
            url:"/tug/screen/checkgamestatus",
            dataType:"json",
            type: "post",
            data:{
                "sequence":that.sequence,
				"meet_id":that.meet_id,
                "status" : 0
            },
            success:function(data) {
				console.log(data);
                if(data.recode == 1 ) {
					that.gameStatus(0);
                }else {
					alert("网络请求失败！");
				}
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){

            }
        });
	},
	nocitceScreen:function(value) {
        var http_server = $("input[name='httpserver']").val();
            $.ajax({
                url:http_server+"/item_play",
                dataType:"json",
                type: "post",
                data:{
                    meet_id:that.meet_id,    //年会id
                    params:value           //对应action play方法的参数key
                },
                success:function(data) {
                    if(data.code==0) {

                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){

                }
            });
	},
	//status 为1 开始游戏 , status为0 再来一次 设置游戏状态
	gameStatus:function(status) {
		var data = {
			"sequence":that.sequence,
			"status":status,
			"meet_id":that.meet_id
		};
		$.ajax({
			type:"post",
			url:"/tug/screen/begin",//点击开始游戏
			dataType:"json",
			data:data,
			success:function(ret) {
				if(ret.recode == 1) {
					if(status == 0) {//再来一轮
						that.ongoingObj.style.display = "none";
						that.startObj.style.display = "none";
						that.nobodyObj.style.display = "block";
						that.againObj.style.display = "none";
						//通知大屏
						that.status = 0;
						that.nocitceScreen(0);
						//获取加入游戏人数
						that.gamecheck();
					}
					if(status == 1) { //直接开始游戏
						var time = ret.playtime;
						$.ajax({
							type:"post",
							url:"/tug/screen/getBtnStatus",
							dataType:"json",
							data:data,
							success:function(ret) {
								var res = parseInt(ret.res);
								if(res == 1) {
									/**开始游戏：隐藏开始按钮,显示进行中**/
									that.ongoingObj.style.display = "block";
									that.startObj.style.display = "none";
									that.nobodyObj.style.display = "none";
									that.againObj.style.display = "none";
									//通知大屏
									that.nocitceScreen(1);
								    var timer = setTimeout(function() {
										/**开始游戏：隐藏进行中按钮,显示再来一次按钮**/
										$("#nobody").removeClass("active");
										$("#ongoing").removeClass("active");
										$("#again").removeClass("active");
										that.ongoingObj.style.display = "none";
										that.startObj.style.display = "none";
										that.nobodyObj.style.display = "none";
										that.againObj.style.display = "block";
										that.status=2;
										clearTimeout(timer);
									}, time*1000);
								}
								if(res == -3) {
									alert("参与人数不足");
								}
							},
							error:function(){
								that.isLock = !that.isLock;
							}
						})
					}
				}else if(ret.recode == 2) {
					alert("游戏已开始");
					window.location.reload();
				}
				that.isLock = !that.isLock;
			},
			error:function() {
				that.isLock = !that.isLock;
			}
		})
	},
	gamecheck:function() {
		var data = {"sequence":that.sequence,"meet_id":that.meet_id};
		that.getNumberTimer = setInterval(function() {
			$.ajax({
				"type":"post",
				"url":"/tug/screen/headcount",
				"dataType":"json",
				"data":{sequence:that.sequence,meet_id:that.meet_id},
				success:function(ret) {
					var lNum = parseInt(ret.lNum);
					var rNum = parseInt(ret.rNum);
					//参与人数
					if(rNum > 0 && lNum > 0) {
						if(that.status == 0) {
							that.changeDisplay(that.startObj);
						}
						if(that.status==1) {
							that.changeDisplay(that.ongoingObj);
						}
						if(that.status==2) {
							that.changeDisplay(that.againObj);
						}
					}else{
						that.changeDisplay(that.nobodyObj);
					}
				},
				error:function() {
				}
			})
		},1000);
	},
	changeDisplay:function(obj) {
		that.ongoingObj.style.display = "none";
		that.startObj.style.display = "none";
		that.nobodyObj.style.display = "none";
		that.againObj.style.display = "none";
		obj.style.display = "block";
	},
	//游戏结束
	gameOver:function() {
		that.isLock = !that.isLock;
		var sequence = that.obj.getQueryString("sequence");
		$.ajax({
			type:"post",
			url:"/tug/screen/ready",
			dataType:"json",
			data:{"sequence":sequence,"status":2,meet_id:that.meet_id},
			success:function(ret) {
				that.isLock = !that.isLock;
			},
			error:function() {
				that.isLock = !that.isLock;
			}
		})
	}
}